﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaleta.Network.Serialization;
using Microsoft.Xna.Framework;
using Lidgren.Network;

namespace Kaleta.Outcast.Network
{
    public class ShipSyncDataSerializer : IDataTypeSerialization
    {
        public void WriteData(ref object data, ref NetBuffer sendBuffer)
        {
            ShipSyncData syncData = (ShipSyncData) data;

            sendBuffer.Write(syncData.Position.X);
            sendBuffer.Write(syncData.Position.Y);

            sendBuffer.Write(syncData.Velocity.X);
            sendBuffer.Write(syncData.Velocity.Y);

            sendBuffer.Write(syncData.Acceleration);
            sendBuffer.Write(syncData.Direction);
            sendBuffer.Write(syncData.Rotation);

            sendBuffer.Write((uint) syncData.MovementState);
        }

        public object ReadData(ref NetBuffer readBuffer)
        {
            ShipSyncData data = new ShipSyncData()
            {
                Position = new Vector2()
                {
                    X = readBuffer.ReadSingle(),
                    Y = readBuffer.ReadSingle()
                },
                Velocity = new Vector2()
                {
                    X = readBuffer.ReadSingle(),
                    Y = readBuffer.ReadSingle()
                },
                

                Acceleration = readBuffer.ReadSingle(),
                Direction = readBuffer.ReadSingle(),
                Rotation = readBuffer.ReadSingle(),
                MovementState = (MovementState)readBuffer.ReadUInt32()
            };
            return data;
        }
    }

    

    public struct ShipSyncData 
    {
        public Vector2 Position;
        public Vector2 Velocity;
        public float Acceleration;
        public float Direction;
        public float Rotation;
        public MovementState MovementState;
    }

}
